﻿using ATM.Common;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATM.DAO
{
    public class LogDAO
    {
        private static SqlConnection con;

        public static bool WriteLog(Card card, int logType, int atmID, float amount, string detail)
        {
            try
            {
                con = DataConnection.GetConnection();
                SqlCommand cmd = new SqlCommand("Insert into Logs Values(@LogType,@ATMID,@CardNo,@LogDate,@Amount,@Details)", con);
                cmd.Parameters.Add(new SqlParameter("@LogType", logType));
                cmd.Parameters.Add(new SqlParameter("@ATMID", atmID));
                cmd.Parameters.Add(new SqlParameter("@CardNo", card.CardNo));
                cmd.Parameters.Add(new SqlParameter("@LogDate", DateTime.Now));
                cmd.Parameters.Add(new SqlParameter("@Amount", amount));
                cmd.Parameters.Add(new SqlParameter("@Details", detail));
                int temp = cmd.ExecuteNonQuery();
                if (temp != 0)
                    return true;
                return false;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
